package com.example.bishe.controller;/*
 *@Author yws
 *@Date 2022/3/3 14:13
 */

import com.example.bishe.config.SecurityConfig;
import com.example.bishe.toolclass.MyEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;

@RestController
public class UserLogin {
    @RequestMapping("/ww")
    public void nihao(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println(authentication.getName());//用户名
        System.out.println(authentication.getAuthorities());//拥有的所有角色
        System.out.println(authentication.getPrincipal());
        System.out.println("就问你惊喜不惊喜");
    }
    @Autowired
    AuthenticationManager authenticationManager ;
    @RequestMapping("/log")
    public void ww(){
        UsernamePasswordAuthenticationToken token =new UsernamePasswordAuthenticationToken("YangWanShun","123456");
        Authentication authenticate = authenticationManager.authenticate(token);
        SecurityContextHolder.getContext().setAuthentication(authenticate);
    }

}
